<template>
  <div>
    <Table
      ref="dataTable"
      stripe
      :loading="table.loading"
      :columns="table.tableColumns"
      :data="table.tableRows"
      style="margin-top:20px;"
      @on-select="select" @on-select-cancel="selectCancel"
               @on-select-all="selectAll" @on-select-all-cancel="selectAllCancel"
      @on-sort-change="changeSort"
    ></Table>
    <div style="margin: 20px; overflow: hidden">
      <div style="float: right;">
        <Page
          :total="pager.total"
          :current="pager.pageNo"
          @on-change="changePageNo"
          @on-page-size-change="changePageSize"
          showSizer
          showTotal
        ></Page>
      </div>
    </div>
  </div>
</template>

<script>
import * as utils from '@/api/utils-v2'

export default {
  name: 'GoodsCategoryAttributeTable',
  data() {
    return {
      urls: {
        searchUrl: '/goods-category-attr/admin/pager-cond'
      },
      pager: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      },
			dataDictCodes: ['IS_ACTIVE','GOODS_ATTRIBUTE_REQUIRED','GOODS_ATTRIBUTE_DISPLAY','GOODS_ATTRIBUTE_IS_GROUP'],
			dataDictItems: {},
      searchOpts: {
        sortColumn: 'goodsCategoryAttributeAttrOrder',
        sortOrder: 'asc'
      },
      table: {
        loading: false,
        tableColumns: [
          {
            type: 'selection',
            width: 52,
            key: 'id',
            align: 'center',
            fixed: 'left'
          },
          {
            width: 60,
            align: 'center',
            fixed: 'left',
            render: (h, params) => {
              return h(
                'span',
                params.index + (this.pager.pageNo - 1) * this.pager.pageSize + 1
              )
            }
          },
          {
            title: '商品类目编号',
            key: 'goodsCategoryId',
            minWidth: 120,
            sortable: true
          },
          {
            title: '类目名称',
            key: 'goodsCategoryTitle',
            minWidth: 120,
            sortable: true
          },
          {
            title: '商品属性编号',
            key: 'goodsAttributeId',
            minWidth: 120,
            sortable: true,
          },
          {
            title: '属性名称',
            key: 'goodsAttributeAttrName',
            minWidth: 120,
            sortable: true
          },
          {
            title: '属性代码',
            key: 'goodsAttributeAttrCode',
            minWidth: 120,
            sortable: true
          },
          {
            title: '数据类型',
            key: 'goodsAttributeAttrType',
            minWidth: 120,
            sortable: true
          },
          {
            title: '数据长度',
            key: 'goodsAttributeAttrLength',
            minWidth: 120,
            sortable: true
          },
          {
            title: '是否必填',
            key: 'goodsAttributeAttrRequired',
            minWidth: 120,
            sortable: true,
            render: (h, params) => {
                    let dictItem = utils.getDataDictItemDisplayValue(this, 'GOODS_ATTRIBUTE_REQUIRED', params.row.goodsAttributeAttrRequired)
                    return h('span', dictItem.displayValue)
             }
          },
          {
            title: '是否前端显示',
            key: 'goodsAttributeAttrDisplay',
            minWidth: 120,
            sortable: true,
            render: (h, params) => {
                    let dictItem = utils.getDataDictItemDisplayValue(this, 'GOODS_ATTRIBUTE_DISPLAY', params.row.goodsAttributeAttrDisplay)
                    return h('span', dictItem.displayValue)
             }
          },
          {
            title: '属性排序',
            key: 'goodsCategoryAttributeAttrOrder',
            minWidth: 120,
            sortable: true
          },
          {
            title: '是否属性组合',
            key: 'goodsCategoryAttributeIsAttrGroup',
            minWidth: 120,
            sortable: true,
            renderHeader: (h, params) => {
              return h('span', [
                h('span', '是否属性组合'),
                h(
                  'Tooltip',
                  {
                    props: {
                      content:
                        '如果是属性组合，则在前端商品详情中可根据此属性进行SKU的组合',
                      placement: 'top',
                      transfer: true,
                      maxWidth: 500
                    }
                  },
                  [
                    h('Icon', {
                      props: {
                        type: 'ios-help-circle'
                      },
                      style: {
                        marginLeft: '3px'
                      }
                    })
                  ]
                )
              ])
            },
			render: (h, params) => {
			        let dictItem = utils.getDataDictItemDisplayValue(this, 'GOODS_ATTRIBUTE_IS_GROUP', params.row.goodsCategoryAttributeIsAttrGroup)
			        return h('span', dictItem.displayValue)
			 }
          },
          {
            title: '版本号',
            key: 'goodsCategoryAttributeVersion',
            minWidth: 120,
            sortable: true,
            renderHeader: (h, params) => {
              return h('span', [
                h('span', '版本号'),
                h(
                  'Tooltip',
                  {
                    props: {
                      content: '类目属性版本号',
                      placement: 'top',
                      transfer: true,
                      maxWidth: 500
                    }
                  },
                  [
                    h('Icon', {
                      props: {
                        type: 'ios-help-circle'
                      },
                      style: {
                        marginLeft: '3px'
                      }
                    })
                  ]
                )
              ])
            }
          },
          {
            title: '创建时间',
            key: 'goodsCategoryAttributeCreateTime',
            minWidth: 120,
            sortable: true,
            renderHeader: (h, params) => {
              return h('span', [
                h('span', '创建时间'),
                h(
                  'Tooltip',
                  {
                    props: {
                      content: '类目属性创建时间',
                      placement: 'top',
                      transfer: true,
                      maxWidth: 500
                    }
                  },
                  [
                    h('Icon', {
                      props: {
                        type: 'ios-help-circle'
                      },
                      style: {
                        marginLeft: '3px'
                      }
                    })
                  ]
                )
              ])
            }
          },
          {
            title: '更新时间',
            key: 'goodsCategoryAttributeUpdateTime',
            minWidth: 120,
            sortable: true,
            renderHeader: (h, params) => {
              return h('span', [
                h('span', '更新时间'),
                h(
                  'Tooltip',
                  {
                    props: {
                      content: '类目属性更新时间',
                      placement: 'top',
                      transfer: true,
                      maxWidth: 500
                    }
                  },
                  [
                    h('Icon', {
                      props: {
                        type: 'ios-help-circle'
                      },
                      style: {
                        marginLeft: '3px'
                      }
                    })
                  ]
                )
              ])
            }
          },
          {
            title: '是否激活',
            key: 'goodsCategoryAttributeIsActive',
            minWidth: 120,
            sortable: true,
            renderHeader: (h, params) => {
              return h('span', [
                h('span', '是否激活'),
                h(
                  'Tooltip',
                  {
                    props: {
                      content: '类目属性是否激活',
                      placement: 'top',
                      transfer: true,
                      maxWidth: 500
                    }
                  },
                  [
                    h('Icon', {
                      props: {
                        type: 'ios-help-circle'
                      },
                      style: {
                        marginLeft: '3px'
                      }
                    })
                  ]
                )
              ])
            },
			render: (h, params) => {
			        let dictItem = utils.getDataDictItemDisplayValue(this, 'IS_ACTIVE', params.row.goodsCategoryAttributeIsActive)
			        return h('span', dictItem.displayValue)
			 }
          },

          {
            title: '操作',
            key: 'action',
            width: 80,
            align: 'center',
            fixed: 'right',
            render: (h, params) => {
              return h('div', [
                h(
                  'Button',
                  {
                    props: {
                      type: 'primary',
                      size: 'small'
                    },
                    style: {
                      marginRight: '5px'
                    },
                    on: {
                      click: () => {
                        this.showDetail(params.row)
                      }
                    }
                  },
                  '详情'
                )
              ])
            }
          }
        ],
        tableRows: [],
        selections: []
      }
    }
  },
  computed: {},
  mounted() {
    this.search()
  },
  methods: {
    search() {
      this.$emit('searchTable')
    },
    showDetail(row) {
      this.$emit('showDetailModal', JSON.parse(JSON.stringify(row)))
    },
    select(selections, row) {
              utils.select(this, selections, row)
            },
            selectCancel(selections, row) {
              utils.selectCancel(this, selections, row)
            },
            selectAll(selections) {
              utils.selectAll(this, selections)
            },
            selectAllCancel(selections) {
              utils.selectAllCancel(this, selections)
            },
    changeSort(sortColumn) {
      utils.changeSort(this, sortColumn)
    },
    changePageNo(pageNo) {
      utils.changePageNo(this, pageNo)
    },
    changePageSize(pageSize) {
      utils.changePageSize(this, pageSize)
    }
  }
}
</script>

<style>
</style>
